﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MS_UI
{
    public partial class FlowPipe : UserControl
    {
        public FlowPipe()
        {
            InitializeComponent();
            //定时器
            Timer myTimer = new Timer();
            //500毫秒刷新一次
            myTimer.Interval = 500;
            //触发事件
            myTimer.Tick += myTimer_Tick;
            //启动
            myTimer.Enabled = false;
        }

        private void myTimer_Tick(object sender, EventArgs e)
        {
            //绘制图画
           // this.Invalidate();
        }

        //画布
        Graphics g;
        int width;
        int heigth;
        public bool IsActive { get; set; }
        //流动颜色
        Color runColor = Color.FromArgb(128,128,255);
        public Color RunColor
        {
            get
            {
                return runColor;
            }
            set
            {
                runColor = value;
            }
        }
        //开始颜色
        Color startColor = Color.FromArgb(73,73,73);
        public Color StartColor
        {
            get { return startColor; }
            set { startColor = value; }
        }
        //结束颜色
        //开始颜色
        Color endColor = Color.FromArgb(247,247,247);
        public Color EndColor
        {
            get { return endColor; }
            set { endColor = value; }
        }
        //定义流动条长度
        int length = 10;
        public int Length { get { return length; } set { length = value; } }
        // 定义流动条宽度占比
        private double extent = 0.75;
        public double Extent
        {
            get { return extent; }
            set { extent = value; }
        }
        //定义流动条间距
        private int space = 5;
        public int Space
        {
            get { return space; } set { space = value; }
        }
        //流动条速度
        private int speed = 5;
        public int Speed
        {
            get { return speed; }
            set
            {
                speed = value;
            } 
        }
        //方向
        private bool isVertical = false;
        public bool IsVertical
        {
            get { return IsVertical; }
            set
            {
                IsVertical = value;
            } 
        }
        //流动状态,1 从左到右，2 从右到左
        // 3 从上倒下，4 从先道上
        private int flowNum = 1;
        public int FlowNum
        {
            get { return flowNum; }
            set { flowNum = value; }
        }
        //重绘
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //获取画布对象
            g = e.Graphics;
            //画质质量，抗锯齿 ,平滑
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //高质量
            g.SmoothingMode = SmoothingMode.HighQuality;
            width = this.Width; // 画布宽
            heigth = this.Height; //画布高
            //绘制第一步，绘制渐变色外框
            //拿到刷子
            LinearGradientBrush brush;
            //矩形
            Rectangle rec1 = new Rectangle(0,0,width,heigth / 2);
            //位置，大小，起始渐变色，结束渐变色，从上往下
            brush = new LinearGradientBrush(rec1,startColor,endColor,LinearGradientMode.Vertical);
            g.FillRectangle(brush, rec1);
        }

    }
}
